Steps for installing Postgresql
Modified from http://wiki.postgresql.org/wiki/Working_with_Eclipse
you can use this link to see the snapshots of the proceedings wherever applicable.
Requirements:
- Ubuntu OS, VSCode/Eclipse for C/C++
You can set up PostgreSQL by git clone as below
Setting up PostgreSQL with GIT
git clone -b REL_17_STABLE --single-branch https://git.postgresql.org/git/postgresql.git
Configuring PostgreSQL
- IMPORTANT
Follow the steps in
Steps in building and running PostgreSQL to set up environment variables and then configure, build, and install postgresql.
- In case the make fails during build due to missing libraries, make
sure they are installed using your Ubuntu software center or synaptic
package manager (or equivalent).
Some of the packages that are often missing and needed are:
- libreadline6-dev
- zlib1g-dev
- bison
- flex
Configuring VSCode for PostgreSQL Debugging
Create a launch.json file as below (change the paths to where you have set up postgresql on your machine.
For Linux
{ {
"version": "0.2.0",
"configurations": [
{
"name": "PostgreSQL Launch",
"type": "cppdbg",
"request": "launch",
"program": "/home/sudarsha/Code/postgresql/install/bin/postgres",
"args": ["--single", "-D", "/home/sudarsha/Code/postgresql/install/data", "test"],
"stopAtEntry": false,
"cwd": "/home/sudarsha/Code/postgresql",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
For MacOS
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [ {
"name": "Debug postgresql",
"type": "cppdbg",
"request": "launch",
"program": "/Users/ssudarshan/Code/postgresql/install/bin/postgres", // Path to your executable
"args": ["--single", "-D", "/Users/ssudarshan/Code/postgresql/install/data", "test"],
"stopAtEntry": false,
"cwd": "/Users/ssudarshan/Code/postgresql", // "${fileDirname}",
"environment": [],
"externalConsole": true, // Set to true if your program needs console input/output
"MIMode": "lldb"
}
]
}
Run Configurations in Eclipse:
-
First make sure you have configured postgresql, created a database, run postgresql in single mode successfully.
After that, switch back to Eclipse.
Select the Project Explorer view. If you cannot see it, add it with the button in the left bottom.
In the Project Explorer view right click on the Projectname (postgres or postgresql-14), and select "Run As >> Run Configurations".
- Select "C/C++ Application:", and click on the new configuration button on the top left (the text on the right helps you identify the button).
The path to the postgres binary should be added in the box titled C/C++ application; for example, "/home/sudarsha/git/postgresql14/install/bin/postgres"
- Switch to the tab "Arguments". At "Program arguments" type the arguments
"--single -D PGDATADIR test"
where PGDATADIR is the directory where the database was created, e.g "/home/sudarsha/git/postgresql/install/data"
and test is the name of the database you created following the instructions in
http://www.cse.iitb.ac.in/dbms/Data/Courses/CS631/PostgreSQL-Resources/pgsql_demo.txt
Then click the "Apply" button. Click "Run" to start the program.
should see following in your console:
PostgreSQL stand-alone backend 14.5
backend>
You can run your commandss here, and you can press ctrl-D to exit.
To start up the console again, choose the project,
and click on the Run button (a green button with a play/rightarrow symbol)
(In server mode you will see the message:
LOG: database system was shut down at (current date and time) UTC
LOG: database system is ready to accept connections
LOG: autovacuum launcher started
)
That means, the installation was successful and the server is running.
Downloading PostgreSQL with Eclipse Using GIT
We recommend using the command line to download postgresql using git.
But if you want to do it from the eclipse IDE you can do it as below.
- Eclipse should have git built in. If your version does not, first install git support by using Help > Install New Software).
- Open File => Import, select Git => Projects from Git and click Next.
Select "URI" and click Next.a
Now you will have to enter the repository's location as
https://git.postgresql.org/git/postgresql.git
- Deselect all branches, then select 14 (or 14.5) Stable and proceed to clone Postgresql.
- After this software is downloaded, which may take a while. Finally you will come to a software import wizard. Choose New Project Wizard and
click on next.
- Select the C/C++, Makefile Project with Existing Code and
click next; you will then have to enter the code location which will
be of the form "homedir/git/postgresql" (replace "homedir" with your
home directory path, e.g. /home/sudarsha).
- Click on Finish
- Your project should now be ready (under the name "postgresql")
- Don't try building your project using eclipse yet. First run the steps for postgresql configurations before doing a make.